import { getCityList } from "@/api/user.js";


export const getCityNameByCityCode = (cityCode) => {
  return new Promise((resolve, reject) => {
    // 获取当前城市code
    getCityList({}).then(res=> {
      const result = res.result
      if (result.length > 0) {
        const targetCity = result.find(item => item.cityCode == cityCode)
        if (targetCity) {
          resolve(targetCity.cityName)
        } else {
          uni.showToast({
            title: '飞猪不支持当前城市',
            icon: 'none',
          })
          reject()
        }
      } else {
        uni.showToast({
          title: '飞猪不支持当前城市',
          icon: 'none',
        })
        reject()
      }
    })
  })
}
/**
 * 根据枚举值获取枚举名称
 */
export const getDictNameByVal = (val, propKey, targetObject = {}) => {
  const list = targetObject[propKey]
  if (list) {
    const target = list.find(item => item.val == val)
    if (target) return target.name
  }

  return val
}

